<?php
namespace app\index\model;
use app\index\model\Issue;
use app\index\model\Ticket;
use think\Model;

class Ticket extends Model
{	
	protected $resultSetType = 'collection';
	//优惠卷显示
	public function index()
	{
		$ticket = new ticket();
		$data = model('ticket')
			->alias('t')
			->join('issue', 't.issueid=issue.id', 'left')
			->field('t.*, issue.name')
			->select();
		foreach($data as $value)
		{
			$arr[] = $value->toArray();
		}
		return $arr;
	}
	//优惠卷添加
	public function add($data)
	{
		$data = model('ticket')
				->insert([
					'money' => input('money'),
					'min' => input('min'),
					'stoptime' => input('stoptime'),
					'intergral' => input('intergral'),
					'comment' => input('comment'),
					'issueid' => input('name'),
					'number' => input('number'),
					'surplus' => input('number')
		]);
		return $data;
	}
	//优惠卷根据修改id查询
	public function edits($id)
	{
		$data = model('ticket')
			->alias('t')
			->join('issue', 't.issueid=issue.id', 'left')
			->field('t.*, issue.name,issue.id as iid')
			->where('t.id',$id)
			->find();
			//echo $this->getlastSql();die;
		// $result = $data['stoptime'];
		// $results = explode(" ",$result));
		return $data;
	}
	//优惠卷修改
	public function uedit($id,$money,$min,$stoptime,$intergral,$comment,$issueid,$number)
	{
		$ticket = new Ticket();
		$data = $ticket->save([
            'money' => $money, 
			'min' => $min,
			'stoptime' => $stoptime,
			'intergral' => $intergral,
			'comment' => $comment,
			'issueid' => $issueid,
			'number' => $number
                ],['id' => $id]);
		return $data;
	}
}